package br.com.advance.automacao.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "MTBF")
@NamedQueries({@NamedQuery(name=MTBF.BUSCAR_MTBF_POR_FILTRO, query="select e from MTBF e join fetch e.clp c WHERE c.id = :idCLP "
		+ " AND e.turno.id = :idTurno AND e.data = :data "),
		@NamedQuery(name=MTBF.DELETAR_MTBF_POR_CLP_DATA_TURNO, query=" DELETE FROM MTBF e where e.turno.id=:idTurno and e.data = :data and e.clp.id = :idCLP ")
})
public class MTBF {

	public static final String BUSCAR_MTBF_POR_FILTRO = "MTBF.BUSCAR_MTBF_POR_FILTRO";
	public static final String DELETAR_MTBF_POR_CLP_DATA_TURNO = "MTBF.DELETAR_MTBF_POR_CLP_DATA_TURNO";
	
	@Id
    @Column(name = "ID")
	@GeneratedValue
	private Long id;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ID_CLP", referencedColumnName="ID")
	private CLP clp;

	@Column(name = "VALOR", nullable=false, columnDefinition="DOUBLE")
	private Double valor;

	@Column(name = "DATA", nullable=false)
	@Temporal(TemporalType.DATE)
	private Date data;

	@Column(name = "HORA", nullable=false)
	@Temporal(TemporalType.TIME)
	private Date hora;

	@Column(name = "DATA_HORA", nullable=false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date dataHora;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ID_TURNO", referencedColumnName="ID")
	private Turno turno;

	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Double getValor() {
		return valor;
	}
	public void setValor(Double valor) {
		this.valor = valor;
	}
	public CLP getClp() {
		return clp;
	}
	public void setClp(CLP clp) {
		this.clp = clp;
	}
	public Date getData() {
		return data;
	}
	public void setData(Date data) {
		this.data = data;
	}
	public Date getHora() {
		return hora;
	}
	public void setHora(Date hora) {
		this.hora = hora;
	}
	public Date getDataHora() {
		return dataHora;
	}
	public void setDataHora(Date dataHora) {
		this.dataHora = dataHora;
	}
	public Turno getTurno() {
		return turno;
	}
	public void setTurno(Turno turno) {
		this.turno = turno;
	}

}
